/*
 * @Descripttion: 功能点管理
 * @Author: YuZhenJing
 * @Date: 2020-01-15 11:53:09
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-03-20 15:34:35
 */

/**
 * 查询功能点默认选中数据集
 */
export function searchDefaultSelectOptions() {
  const options = this.$html.get('menu/defaultSelectOptions')
  options
    .then(data => {
      if (data.returnType == 'success') {
        this.defaultSelectOptions = this.$objTools.dicToArray(data.returnData)
      }
    })
    .catch(() => {
      console.log('error:defaultSelectOptions')
    })
}

/**
 * 查询功能点信息
 */
export function request() {
  this.tableDataParam.loading = true
  let param = {
    pageSize: this.tableDataParam.paginationData.pageSize,
    pageIndex: this.tableDataParam.paginationData.currentPage,
    filter: this.searchParams,
    sortBy: this.tableDataParam.paginationData.sortItem.prop,
    descending:
      this.tableDataParam.paginationData.sortItem.order == 'descending'
  }
  const options = this.$html.get('menu/funPointsPagedList', param)
  options
    .then(res => {
      let data = res.returnData
      this.tableDataParam.data = data.list
      this.tableDataParam.paginationData.total = data.total
      this.tableDataParam.loading = false
    })
    .catch(() => {
      this.tableDataParam.loading = false
      console.log('error:menuPointsList/request')
    })
}

/**
 * 增加功能点
 */
export function addPoints() {
  this.$refs.menuPointsAddRef.show(this.searchParams.funListCode)
}

/**
 * 删除功能点
 */
export function delPoints(rowObj) {
  this.$confirm('确认要删除【' + rowObj.funPointsName + '】吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      const delResult = this.$html.delete(
        'menu/delPoints',
        rowObj.funPointsCode
      )
      delResult
        .then(data => {
          if (data.returnType == 'success') {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success'
            })
            this.request()
          }
        })
        .catch(() => {
          console.log('error:menu/delPoints')
        })
    })
    .catch(() => {
      this.$notify.info({
        title: '消息',
        message: '已取消删除'
      })
    })
}

/**
 * 编辑功能点
 */
export function editPoints(rowObj) {
  this.$refs.menuPointsEditRef.show(rowObj)
}
